//
// Created by sjjmw on 2/23/2022.
//

#ifndef LEETCODE__17_H
#define LEETCODE__17_H

//todo
// 假设有k个人质和k个绑匪围成一圈。人质的编号从1到k，绑匪的编号从k+1到2k。
// 从编号1开始，每次从其中选出第m个人(隔m-1选出一人)出列。
// 希望求出m的最小值，使得最先出列的k个人都是绑匪，即都是编号从k+1到2k的人。
#include "iostream"

struct Time {
    int year;
    int month;
    int day;

//    Time(int year1,int month1,int day1):
//    year(year1),month(month1),day(day1)
//    {
//
//    }
    void copy_from(Time t) {
        this->year = t.year;
        this->day = t.day;
        this->month = t.month;
    }

    bool later_than(Time t) {
        if (t.year < this->year) {
            return true;
        } else if (t.year == this->year){
            if (t.month < this->month) {
                return true;
            } else if (t.month == this->month){
                if (t.day < this->day) {
                    return true;
                } else{
                    return false;
                }
            }else{
                return false;
            }
        }else{
            return false;
        }
    }
};

int main() {
    int set_cnt;
//    std::cin>>set_cnt;
    while (scanf("%d", &set_cnt) != EOF) {
        int cj = 1;
        if (set_cnt == 0) {
            continue;
        }
        Time early, late;
        std::cin >> early.year >> early.month >> early.day;
        late = early;
        set_cnt--;

        while (set_cnt) {
            int in;
            Time a;
            std::cin >> a.year>>a.month>>a.day;
            if(a.later_than(late)){
                late=a;
            }
            if(early.later_than(a)){
                early=a;
            }
            set_cnt--;
        }
        printf("%d %d %d\n", late.year,late.month,late.day);
        printf("%d %d %d\n", early.year,early.month,early.day);
    }
    return 0;
}


#endif //LEETCODE__17_H
